package com.xxx.service.impl;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xxx.common.IdWorkerManage;
import com.xxx.common.dto.Page;
import com.xxx.common.dto.Pagination;
import com.xxx.dao.SysRoleDao;
import com.xxx.model.SysRole;
import com.xxx.service.SysRoleService;

@Service
public class SysRoleServiceImpl implements SysRoleService {
	
	@Autowired
	private SysRoleDao sysRoleDao;
	
	@Override
	@Transactional
	public long saveOrUpdate(SysRole sysRole) throws Exception {
		if(sysRole.getId() == null){
			sysRole.setId(IdWorkerManage.getId());
			return sysRoleDao.save(sysRole);
		}
		return sysRoleDao.update(sysRole);
	}

	@Override
	@Transactional
	public boolean delete(long id) throws Exception{
		return sysRoleDao.delete(id);
	}

	@Override
	public SysRole getEntity(long id) throws Exception{
		return sysRoleDao.getEntity(id);
	}

	@Override
	public int getCount(Map<String, Object> whereMap) {
		return sysRoleDao.getCount(whereMap);
	}
	
	@Override
	public List<SysRole> getList(Map<String, Object> whereMap) {
		return sysRoleDao.getList(whereMap);
	}

	@Override
	public List<SysRole> getList(Map<String, Object> whereMap, Pagination pagination) {
		return sysRoleDao.getList(whereMap, pagination);
	}
	
	@Override
	public Page<SysRole> getPage(Map<String, Object> whereMap, Pagination pagination) {
		int count = this.getCount(whereMap);
		if(count > 0){
			List<SysRole> list = this.getList(whereMap, pagination);
			return new Page<SysRole>(pagination.getCurrentPage(), pagination.getPageSize(), count, list);
		}
		return new Page<SysRole>(pagination.getCurrentPage(), count);
	}
}
